package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.net.BaseCallBack;
import com.zlzxm.shoesmarket.net.RequestTip;
import com.zlzxm.shoesmarket.net.repository.RecruitRepository;
import com.zlzxm.shoesmarket.net.respone.BaseResponse;
import com.zlzxm.shoesmarket.net.respone.RpRecruit;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityRecruit;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;

/**
 * CREATE BY zlzxm ON 4/23/21
 */
public class VMRecruit extends BaseViewModel {

    RecruitRepository recruitRepository = new RecruitRepository();

    private MutableLiveData<List<EntityRecruit>> liveRecruit = new MutableLiveData<>();


    public MutableLiveData<List<EntityRecruit>> getLiveRecruit() {

        return liveRecruit;
    }

    public void requestList(){

        recruitRepository.recruitList()
                .compose(RxAndroidHelp.turn())
                .subscribe(new BaseCallBack<List<RpRecruit>>(){


                    @Override
                    protected void succeed(String msg,List<RpRecruit> source) {

                        liveRecruit.setValue(createData(source));
                    }

                    @Override
                    protected void failed(String msg) {

                    }

                    @Override
                    protected void notLogin() {

                    }
                },throwableCallback);


    }

    //<editor-fold defaultState="collapsed" desc="测试">

    public List<EntityRecruit> createData(List<RpRecruit> source){

        List<EntityRecruit> list = new ArrayList<>();

        for (RpRecruit bean : source) {

            EntityRecruit entityRecruit = new EntityRecruit();
            entityRecruit.setContent(bean.getContent());

            list.add(entityRecruit);

        }



        return list;

    }


    // </editor-fold>



}
